#include "drv_led.h"
#include "drv_beep.h"
#include "drv_key.h"
#include "drv_usart.h"
#include "drv_exti.h"
#include "string.h"
#include "drv_time.h"
#include "drv_iic.h"
#include "oled.h"
#include "bmp.h"

uint8_t key_flag1 = 0;
uint8_t key_flag2 = 1;
uint8_t key_flag3 = 2;
uint8_t key_flag4 = 3;

uint8_t dir = 0;
uint32_t led_pwm = 0;

u8 t=' ';


int main()
{
//	drv_beep_init();
	drv_led_init();//led灯初始化
	drv_systick_init(168);//systick定时器初始化
//	drv_key_init(GPIOE,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6);//按键初始化
//	drv_key_init2(GPIOC,GPIO_Pin_13);
	drv_usart_init();//串口初始化
	drv_exti_init();
//	drv_time6_init();
	drv_time1_init();
	drv_iic_init();
	OLED_Init();
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//选择中断组

	
	//OLED屏幕
		OLED_ShowPicture(0,0,128,64,BMP1,1);
		OLED_Refresh();
		drv_systick_delayms(500);
		OLED_Clear();

		OLED_ShowChinese(16,0,0,16,1);
		OLED_ShowChinese(42,0,1,16,1);
		OLED_ShowChinese(68,0,2,16,1);
		OLED_ShowChinese(94,0,3,16,1);
		OLED_ShowString(8,16,"HUAQINGYUANJIAN",16,1);
		OLED_ShowString(20,32,"2024/03/06",16,1);
		OLED_ShowString(0,48,"ASCII:",16,1);  
		OLED_ShowString(63,48,"CODE:",16,1);
		OLED_ShowChar(48,48,t,16,1);//显示ASCII字符	   
		t++;
		if(t>'~')t=' ';
		OLED_ShowNum(103,48,t,3,16,1);
		OLED_Refresh();
//		drv_systick_delayms(500);
//		OLED_Clear();
//		OLED_ShowChinese(0,0,0,16,1);  //16*16 中
//	  OLED_ShowChinese(16,0,0,24,1); //24*24 中
//		OLED_ShowChinese(24,20,0,32,1);//32*32 中
//	  OLED_ShowChinese(64,0,0,64,1); //64*64 中
//		OLED_Refresh();
//	  drv_systick_delayms(500);
//  	OLED_Clear();
//		OLED_ShowString(0,0,"ABC",8,1);//6*8 “ABC”
//		OLED_ShowString(0,8,"ABC",12,1);//6*12 “ABC”
//	  OLED_ShowString(0,20,"ABC",16,1);//8*16 “ABC”
//		OLED_ShowString(0,36,"ABC",24,1);//12*24 “ABC”
//	  OLED_Refresh();
//		drv_systick_delayms(500);
		//OLED_ScrollDisplay(11,4,1); 
	
	printf("hello 2311 class \r\n");
	
	while(1)
	{
	/*
		if(key_flag3 == 2 )
		{
			drv_led_close(GPIO_Pin_10);
			drv_beep_open();
		}
		else
		{
			drv_led_open(GPIO_Pin_10);
			drv_beep_close();
		}
		
		if(dir == 0)
		{
				led_pwm++;
		}
		else
		{
				led_pwm--;
		}
		if(led_pwm > 300)
		{
			dir = 1;
		}	
		if(led_pwm == 0)
		{
			dir = 0;
		}
		TIM_SetCompare1(TIM1,led_pwm);
		drv_systick_delayms(10);
		*/
	}
}





#if 0
int main(void)
{
	drv_led_init();//led灯初始化
	drv_systick_init(168);//systick定时器初始化
	drv_key_init(GPIOE,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6);//按键初始化
	drv_key_init2(GPIOC,GPIO_Pin_13);
	drv_usart_init();//串口初始化
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//选择中断组
	printf("hello 2311 class \r\n");

	while(1)
	{
		if(key_flag4 == 3 )
		{
			if(key_flag1 == 0 )
			{
					drv_led_close(GPIO_Pin_8);
			}
			else
			{
					drv_led_open(GPIO_Pin_8);
			}
			if(key_flag2 == 1 )
			{
					drv_led_close(GPIO_Pin_9);
			}
			else
			{
					drv_led_open(GPIO_Pin_9);
			}
			if(key_flag3 == 2 )
			{
					drv_led_close(GPIO_Pin_10);
			}
			else
			{
					drv_led_open(GPIO_Pin_10);
			}
		}
		else
		{
			drv_led_open(GPIO_Pin_8);
			drv_systick_delayms(500);
			
			drv_led_open(GPIO_Pin_9);
			drv_systick_delayms(500);

			drv_led_open(GPIO_Pin_10);
			drv_systick_delayms(500);
			
			drv_led_close(GPIO_Pin_10);
			drv_led_close(GPIO_Pin_9);
			drv_led_close(GPIO_Pin_8);
			drv_systick_delayms(500);
		}
		
		//获取键值
		if(get_key_value(GPIOE,GPIO_Pin_4))
		{
			key_flag1 = ~key_flag1;
		}
		if(get_key_value(GPIOE,GPIO_Pin_5))
		{
			key_flag2 = ~key_flag2;
		}
		if(get_key_value(GPIOE,GPIO_Pin_6))
		{
			key_flag3 = ~key_flag3;
		}
		if(get_key_value(GPIOC,GPIO_Pin_13))
		{
			key_flag4 = ~key_flag4;
		}
		drv_systick_delayms(10);		
	}
}
#endif
